package org.ibetyoudid.adjustremote;

import java.util.HashMap;

import org.ibetyoudid.adjustremote.R;

import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.view.KeyEvent;

public class MyLogger {
	public static final int HELLO_ID = 0;
	private static HashMap<Integer,String> keycodes = new HashMap<Integer, String>();
	public static void log(Context context ,String text, int id) {
		if (Params.LOGGING_ENABLED) {
			Log.i(Params.LOGGING_TAG, text);

			String ns = Context.NOTIFICATION_SERVICE;
			NotificationManager nm = (NotificationManager) context.getSystemService(ns);
			
			
			Intent notificationIntent = new Intent(context, MyLogger.class);
			PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0);

			Notification n = new Notification(R.drawable.icon, text, System.currentTimeMillis());
			n.setLatestEventInfo(context, text.substring(0, 10)+"...", text, contentIntent);

			nm.notify(HELLO_ID, n);
		}
	}
	public static void log(Context context ,String text) {
		MyLogger.log(context, text,MyLogger.HELLO_ID);
	}
	public static void logTranslate(Context context, int cur_key_code, int tranlated_code) {
		if(keycodes.isEmpty()) {
			keycodes.put(KeyEvent.KEYCODE_MEDIA_NEXT, 		"MEDIA_NEXT");
			keycodes.put(KeyEvent.KEYCODE_MEDIA_PREVIOUS, 	"MEDIA_PREVIOUS");
			keycodes.put(KeyEvent.KEYCODE_VOLUME_DOWN, 		"VOLUME_DOWN");
			keycodes.put(KeyEvent.KEYCODE_VOLUME_UP, 		"VOLUME_UP");
		}
		String text = "" + keycodes.get(new Integer(cur_key_code)) 
					+ " -> " + keycodes.get(new Integer(tranlated_code));
		MyLogger.log(context, text);
		
	}
}
